﻿using LianXi1013.Entity.User;
using LianXi1013.Repostory.User;
using LianXi1013.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LianXi1013.Service.User
{
    public class UserInforService : IUserInforService
    {
        private readonly IUserInforRepostory userInforRepostory;

        public UserInforService(IUserInforRepostory userInforRepostory)
        {
            this.userInforRepostory = userInforRepostory;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UserInfor LoginUser(string name, string password)
        {
            return userInforRepostory.LoginUser(name, password);
        }


        public ReturnedValeDTO AddUser(UserInfor u)
        {
            ReturnedValeDTO dto = new ReturnedValeDTO();
            var user = userInforRepostory.GetUserName(u.UserName);
            if (user != null)
            {
                dto.Code = 0;
                dto.Message = "用户名已被注册，请重新输入";
                return dto;
            }
            var adduser = userInforRepostory.AddUser(u);
            if (adduser == true)
            {
                dto.Code = 1;
                dto.Message = "注册成功";
            }
            return dto;
        }
    }
}
